import BinarySearchTreeNode from './BinarySearchTreeNode';


// 左边比根节点小 右边大

export default class BinarySearchTree {
  /**
   * @param {function} [nodeValueCompareFunction]
   */
  constructor(nodeValueCompareFunction) {
    this.root = new BinarySearchTreeNode(null, nodeValueCompareFunction);

    // Steal node comparator from the root.
    this.nodeComparator = this.root.nodeComparator;
  }

  /**
   * @param {*} value
   * @return {BinarySearchTreeNode}
   */
  insert(value) {
    return this.root.insert(value);
  }

  /**
   * @param {*} value
   * @return {boolean}
   */
  contains(value) {
    return this.root.contains(value);
  }

  /**
   * @param {*} value
   * @return {boolean}
   */
  remove(value) {
    return this.root.remove(value);
  }

  /**
   * @return {string}
   */
  toString() {
    return this.root.toString();
  }

  preorder(node) {
    if(node) {
      console.log(node.value)
      this.preorder(node.left)
      this.preorder(node.right)
    }
  }

  postorder(node) {
    if(node) {
      this.postorder(node.left)
      this.postorder(node.right)
      console.log(node.value)
    }
  }
  inorder(node) {
    if(node) {
      this.inorder(node.left)
      console.log(node.value)
      this.inorder(node.right)
    }
  }
}